<!-- 出库总单 -->
<template>
  <div class="page-container">
    <page_breadcrumb :getKeyMethod="init_table_model" @change="change_table_model" />
    <ex_super_table_page v-bind="option" ref="SuperTablePage" @selection-change="e => selection = e"
      :cell-class-name="cellClassMethod" >



    </ex_super_table_page>


    <ex_super_dialog_form ref="formDialogCheckout" :title="$tt('label_checkout_confirm')" v-bind="dialogBindCheckout"
      @afterSubmitSuccess="checkoutSuccess">
      <template v-slot:dialog_bottom>
        <div class="flex_row_center card margin-small">
          <i class="el-icon-warning color_warning el-icon--left icon-small" />
          <p>{{ $tt('text_outbound_confirm_tip_info') }}</p>
        </div>
      </template>

    </ex_super_dialog_form>


    <ex_super_dialog_form ref="formDialogWithdraw" :title="$tt('label_withdraw_outbound_total_code')"
      v-bind="dialogBindWithdraw">
      <template v-slot:rows="{ formData }">
        <el-form-item :label="$tt('label_specification_detail')">

          <ex-confirm-button :disabled="dialogWithdrawSelectList.length == 0" :label="$tt('label_select_withdraw')" :message="$tt('tip_confirm_to_withdraw')"
            @afterOperationDone="() => withdrawMultiple(dialogWithdrawSelectList, formData)" type="danger" />
          <ex_super_table v-bind="dialogBindWithdrawTable" :data="formData.rows"
            @selection-change="e => dialogWithdrawSelectList = e"></ex_super_table>
        </el-form-item>
      </template>
    </ex_super_dialog_form>

    <detail_transfer_totalOrder ref="detail_transfer_totalOrder" />
  </div>
</template>
<script>






import superTablePageFunction from '@/mixin/super-table-page-function';
import detail_transfer_totalOrder from '@/component/dialog/detail_transfer_totalOrder.vue';
import emitOnFunction from '@/mixin/emit-on-function';
let emitKey = 'wms>transfer>checkout_total_order'
import page_table_model_manage from '@/mixin/page_table_model_manage';
export default {
  title: "title_transfer_checkout_total_order",
  mixins: [superTablePageFunction, emitOnFunction(emitKey), page_table_model_manage],
  components: { detail_transfer_totalOrder, },
  data() {
    return {
      selection: [],

      dialogWithdrawSelectList: [],


      option: {
        search: {
          model: [
            { label: "label_outbound_total_code", key: "code", },
          

            // {
            //   label: "label_destination_warehouse", key: "destinationWarehouseId", type: 'base_warehouse_select', isEnable:true,isTransit:false,
            // },
          ],

        },
        actionExtra: [
          // {
          //   label: 'label_upload_track', attrs: { type: 'primary' },
          //   click: this.$noFunction,
          // },
          // {
          //   label: 'label_upload_track_code',
          //   click: this.$noFunction,
          // },

        ],
        table: {
          url: "/wms-api/inbound/WmsInboundTransitCheckoutTotalOrderRpc/selectPage.json",

          model: this.init_table_model(),

        }
        ,

      },
      dialogBindCheckout: {
        customClass: 'dialog_auto',
        submitUrl: '/wms-api/inbound/WmsInboundTransitCheckoutTotalOrderRpc/checkout.json',
        form: {
          itemClass: "form_item_mini", inputClass: "form_input_small ",
          formClass: "form_mini_col2",
          inline: true,
          model: [
            { key: 'code', label: 'label_outbound_total_code', type: 'text', inputClass: "bold ", itemClass: "form_item_default", },
            { key: 'checkoutPackagingQty', label: 'label_outbound_total_package_count', type: 'text', inputClass: "bold ", },
            { key: 'checkoutBoxQty', label: 'label_outbound_total_box_count', type: 'text', inputClass: "bold ", },
            { key: 'totalWeight', label: 'label_checkout_total_weight', append: 'KG', appendClass: 'input_slot_div_mini' },
            { key: 'totalVolume', label: 'label_checkout_total_volume', append: 'M³', appendClass: 'input_slot_div_mini' },
            { key: 'supplyName', label: 'label_logistics_supplier',type: 'text', inputClass: "bold ",  },
     
            { key: 'trackingNumber', label: 'label_track_code', },
            {
              key: 'checkoutTime', label: 'label_outbound_date', type: 'date-picker', itemClass: "form_item_default",
              attrs: { type: 'datetime' }
            },
          ],
          rules: {
            checkoutTime: { required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' },
            totalWeight: { required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' },
            totalVolume: { required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' },
          },
        }
      },
      dialogBindWithdraw: {
        customClass: 'dialog_auto',
        detailUrl: "/wms-api/inbound/WmsInboundTransitCheckoutTotalOrderRpc/selectDetail.json",

        form: {
          inputClass: "form_input_big",

          model: [
            { key: 'code', label: 'label_outbound_total_code', type: 'text', inputClass: "bold ", itemClass: "form_item_big", },
            { key: 'rows', slot: 'rows', },
          ],
          rules: {
          },
        }
      },
      dialogBindWithdrawTable: {
        model: [
          { type: 'selection', clickToggle: true, },
          { key: 'code', label: 'label_inbound_code', },
          {
            type: 'operate', width: 100, operate: [

              {
                label: 'label_withdraw', type: "confirm-button", message: 'text_confirm_sure_withdraw',
                buttonClass: "button_text_danger", confirmButtonType: 'danger',
                done: (row, i, data, res) => this.withdrawSingle(row, row.checkoutTotalOrder)
              },
            ],
          }
        ]
      },

    };
  },



  methods: {
    option_table_model() {
      return [
        {
          type: 'expandDesc', 'width': 100,
          expandDesc: {
            class: "desc_flex_row",
            column: 4, border: true, direction: 'vertical', labelClassName: 'flex_cell', contentClassName: 'flex_cell',
            model: [],
          },
        },
        { key: 'transitWarehouseCode', label: 'label_transit_warehouse', keyShow: 'expandDesc', 'min-width': 100, 'show-overflow-tooltip': true, },
        { key: 'totalWeight', label: 'label_total_weight', keyShow: 'expandDesc', 'min-width': 100, 'show-overflow-tooltip': true, },
        { key: 'totalVolume', label: 'label_total_volume', keyShow: 'expandDesc', 'min-width': 100, 'show-overflow-tooltip': true, },
        { key: 'code', label: 'label_outbound_total_code', 'min-width': 120, 'show-overflow-tooltip': true, },
        { key: 'supplyName', label: 'label_logistics_supplier', 'min-width': 120, 'show-overflow-tooltip': true, },
        { key: 'trackingNumber', label: 'label_track_code', 'min-width': 120, 'show-overflow-tooltip': true, },
        { key: 'status', label: 'label_status', 'width': 120, 'show-overflow-tooltip': true, formatter: (r, c, v, i) => this.$enumShow(v, "CheckoutTotalOrderStatusEnum") },
        { key: 'destinationWarehouseCode', label: 'label_destination_warehouse', 'width': 120, 'show-overflow-tooltip': true, },
        { key: 'checkoutBoxQty', label: 'label_outbound_total_box_count', 'width': 100, },
        { key: 'checkoutPackagingQty', label: 'label_outbound_total_package_count', 'width': 100, },
        { key: 'checkoutTime', label: 'label_checkout_time', 'width': 130, formatter: (r, c, v, i) => this.$dateFormat(v) },
        {
          type: 'operate', width: 160, operate: [
            {
              type: 'more',
              items: [
                { label: 'label_view_detail', click: (row) => this.clickDetail(row) },
                { label: 'label_checkout_confirm',auth:'wms_transfer_checkout_total_order_confirm',
                 disabled: (row) => !['NOT_CHECKOUT'].some(e => e == row.status), click: (row) => this.clickCheckout(row) },
                { label: 'label_view_receivable' },
                { label: 'label_revoke',auth:'wms_transfer_checkout_total_order_edit',
                 disabled: (row) => !['NOT_CHECKOUT'].some(e => e == row.status), click: (row) => this.clickRevoke(row) },
                { label: 'label_withdraw', auth:'wms_transfer_checkout_total_order_edit',disabled: (row) => !['NOT_CHECKOUT'].some(e => e == row.status), click: (row) => this.showWithdrawForm(row) },
              ]
            }
          ]
        }


      ]
    },
    cellClassMethod({ row, column, rowIndex, columnIndex }) {
      if (column.property == 'status') {
        if (row.status == 'NOT_CHECKOUT') {
          return 'color_primary'
        } else if (row.status == 'CHECKOUT_COMPLETED') {
          return 'color_success'
        }
      }
      return ""
    },
    clickDetail(row) {
      this.$refs['detail_transfer_totalOrder'].show({ params: { checkoutTotalOrderId: row.id }, descData: row, forceLoad: true },)
    },

    clickCheckout(e) {
      this.$refs.formDialogCheckout.show({
        id: e.id,
        code: e.code,
        checkoutPackagingQty: e.checkoutPackagingQty,
        checkoutBoxQty: e.checkoutBoxQty,
        totalWeight: null,
        totalVolume: null,
        supplyName: e.supplyName,
        trackingNumber: null,
        checkoutTime: null,
      }, true,)

    },
    checkoutSuccess() {
      this.reload()
      this.$emitPage("transfer=>checkout_list", 'reload')
      this.$emitPage("standard>inbound_manage", "reload")
    },

    clickRevoke(item) {

      this.$confirm(this.$tt('text_is_sure_revoke_outbound_total_oder'), this.$tt('label_tip'), {
        type: 'warning'
      }).then(() => {
        this.submitRevoke(item)
      }).catch(() => {
      });
    },
    submitRevoke(item) {
      this.$ajax({
        url: "/wms-api/inbound/WmsInboundTransitCheckoutTotalOrderRpc/revoke.json",
        method: 'post', type: 'json',
        data: { checkoutTotalOrderId: item.id },
        success: (res) => {
          this.$message.success(this.$tt('tip_submit_success'))
          this.reload()
          this.$emitPage("transfer=>checkout_list", 'reload')
        }
      })
    },
    showWithdrawForm(e) {
      this.$refs.formDialogWithdraw.show({ checkoutTotalOrderId: e.id }, {
        detailDataHandle: (data) => {
          data.rows.forEach(it => {
            it.checkoutTotalOrder = e
          })
          return Object.assign(data, { id: e.id, code: e.code })
        }
      })

    },

    withdrawSingle(row, checkoutTotalOrder) {
      this.$ajax({
        url: "/wms-api/inbound/WmsInboundTransitCheckoutTotalOrderRpc/withdraw.json",
        method: 'post', type: 'json',
        loading: true,
        data: { checkoutTotalOrderId: checkoutTotalOrder.id, receivingIds: [row.id] },
        success: (res) => {
          this.reload()
          this.showWithdrawForm(checkoutTotalOrder)

        }
      })
    },
    withdrawMultiple(list, checkoutTotalOrder) {

      this.$ajax({
        url: "/wms-api/inbound/WmsInboundTransitCheckoutTotalOrderRpc/withdraw.json",
        method: 'post', type: 'json',
        loading: true,
        data: { checkoutTotalOrderId: checkoutTotalOrder.id, receivingIds: list.map(it => it.id) },
        success: (res) => {
          this.reload()
          this.showWithdrawForm(checkoutTotalOrder)
        }
      })
    },
  }
};

</script>
<style></style>
